/**
 *  单条数据模型
 *  @param id
 *  @param categoryId
 *  @param title
 *  @param content
 */

// 导入枚举 种类

import Category from "./CateEnum";
class ItemData {
  // !表示可为空
  id!: number;
  categoryId!: Category;
  title!: string;
  content!: string;
  createTime!: string;
  constructor(
    id: number = -1,
    categoryId: Category = -1,
    title: string = "",
    content: string = ""
  ) {
    this.id = id;
    this.categoryId = categoryId;
    this.title = title;
    this.content = content;
    this.createTime = this.toSelfDateStr(Date.now());
  }

  toSelfDateStr(timeSamp: number): string {
    // 1.将时间戳转化为时间对象
    let time = new Date(timeSamp);
    // 2. 根据时间对象上的getXXX 方法 依次获取年月日 时分，拼接成想要的格式
    let str = `${time.getFullYear()}-${time.getMonth() +
      1}-${time.getDate()} ${time.getHours()}:${
      time.getMinutes() >= 10 ? time.getMinutes() : "0" + time.getMinutes()
    }`;

    return str;
  }
}

export default ItemData;
